package com.blame.onlinemusicserver.controller;

import com.blame.onlinemusicserver.model.User;
import com.blame.onlinemusicserver.service.UserService;
import com.blame.onlinemusicserver.tools.RequestRegister;
import com.blame.onlinemusicserver.tools.ResponseBodyMessage;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public ResponseBodyMessage<User> login(@RequestParam("username") String username,
                                           @RequestParam("password") String password,
                                           HttpServletRequest request){
        return userService.login(username, password, request);

    }

    @RequestMapping("/register")
    public ResponseBodyMessage<Boolean> register(@Valid @RequestBody RequestRegister requestRegister){
        return userService.register(requestRegister.getUsername(), requestRegister.getPassword(), requestRegister.getEmail());
    }
}
